import {
  Button,
  Tabbar,
  TabbarItem,
  Icon,
  Search,
  Swipe,
  SwipeItem,
  Lazyload,
  Tab,
  Tabs,
  Form,
  Field,
  Switch,
  Empty,
  Toast,
  NavBar,
  Stepper,
  ActionSheet,
  Uploader,
  ImagePreview,
  Tag,
  AddressList,
  AddressEdit,
  SubmitBar,
  NumberKeyboard,
  List,
  Cell,
  PullRefresh,
  Overlay,
  Divider,
  CountDown,
  Image,
  Calendar,
  Picker,
  DatetimePicker,
  Popup,
  PasswordInput,
  Loading,
  Checkbox,
  CheckboxGroup,
  Popover,
  Circle,
  Grid,
  GridItem,
  NoticeBar,
  Skeleton 
} from 'vant'
import 'vant/lib/index.css';

const components = {
  Skeleton,
  NoticeBar,
  Button,
  Tabbar,
  TabbarItem,
  Icon,
  Search,
  Swipe,
  SwipeItem,
  Lazyload,
  Tab,
  Tabs,
  Form,
  Field,
  Switch,
  Empty,
  Toast,
  NavBar,
  Stepper,
  ActionSheet,
  Uploader,
  ImagePreview,
  Tag,
  AddressList,
  AddressEdit,
  SubmitBar,
  NumberKeyboard,
  List,
  Cell,
  PullRefresh,
  Overlay,
  Divider,
  CountDown,
  Image,
  Calendar,
  Picker,
  DatetimePicker,
  Popup,
  PasswordInput,
  Loading,
  Checkbox,
  CheckboxGroup,
  Popover,
  Circle,
  Grid,
  GridItem,
}
import { Locale } from 'vant';
import enUS from 'vant/es/locale/lang/en-US';

Locale.use('en-US', enUS);

function install(Vue){
  Object.keys(components).forEach(key => Vue.use(components[key]))
}

export default {install}

// 注册时可以配置额外的选项,懒加载时需要开启
// <img v-lazy="image" />
// Vue.use(Lazyload, {
//   lazyComponent: true, //是否懒加载模块
//   loading: require('@/assets/images/devimg/loading.gif'),
//   error: require('@/assets/images/devimg/errorimg.jpg'),
// });
//vue指令
// Vue.directive('movable',{
//   bind(el){
//     let agent=window.navigator.userAgent.toLowerCase(),start,move,end
//     //判断当前是移动端还是PC，移动端监听touch，PC监听mouse
//     if(["android","iphone","symbianos","windows phone","ipad","ipod"].some(i=>agent.indexOf(i)>0)){ start='touchstart';move='touchmove';end='touchend' }else{ start='mousedown';move='mousemove';end='mouseup' }
//     //添加事件开始监听
//     var clientwidth = document.body.clientWidth  
//     var clientHeight = document.body.clientHeight    
//     el.addEventListener(start,e=>{
//       //读取事件开始时，触摸或鼠标按下的坐标，以及容器当前所在位置，并声明两个函数对象，供后面添加和取消监听用
//       let cur=e.touches?{x:e.touches[0].clientX,y:e.touches[0].clientY}:{x:e.clientX,y:e.clientY},x=el.offsetLeft,y=el.offsetTop,prevent=function(){event.preventDefault()},moveFun=function(){
//         if(event.touches){  
//           var currentx = event.touches[0].clientX-cur.x+x
//           var currenty = event.touches[0].clientY-cur.y+y
//           if(currentx<0){//左边界
//             currentx = 0
//           }
//           if(currentx>clientwidth-100){//右边界
//             currentx = clientwidth-100
//           }
//           if(currenty<0){//上边界
//             currenty = 0
//           }
//           if(currenty>clientHeight-100){//下边界
//             currenty = clientHeight-100
//           }
//           el.style.left = currentx+'px'
//           el.style.top = currenty+'px'
//         }else{
//           var currentx =event.clientX-cur.x+x
//           var currenty = event.clientY-cur.y+y
//           if(currentx<0){//左边界
//             currentx = 0
//           }
//           if(currentx>clientwidth-100){//右边界
//             currentx = clientwidth-100
//           }
//           if(currenty<0){//上边界
//             currenty = 0
//           }
//           if(currenty>clientHeight-100){//下边界
//             currenty = clientHeight-100
//           }
//           el.style.left=currentx+'px'
//           el.style.top=currenty+'px'
//         }
//         //阻止移动端屏幕移动
//         window.addEventListener('touchmove',prevent,{passive:false})
//       }
//       //监听move并修改位置
//       el.addEventListener(move,moveFun)
//       //声明一个移除处理函数对象
//       let endFun=function(){
//         el.removeEventListener(move,moveFun)
//         el.removeEventListener(move,endFun)
//         window.removeEventListener('touchmove',prevent)
//       }
//       //监听到事件结束时，移除start以外的监听
//       el.addEventListener(end,endFun)
//     })
//   }
// })